package com.dlx.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dlx.common.result.Result;
import com.dlx.model.order.RechargeOrderInfo;
import com.dlx.order.service.RechargeOrderInfoService;
import com.dlx.vo.order.RechargeOrderInfoQueryVo;
import com.dlx.vo.order.RechargeOrderReportQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author nglon
 * @since 2021-11-16
 */
@RestController
@RequestMapping("/admin/order/rechargeOrder")
public class RechargeOrderInfoController {

    @Autowired
    private RechargeOrderInfoService rechargeOrderInfoService;

    @PostMapping("{current}/{limit}")
    public Result pageListRechargeOrderInfo(
            @PathVariable Long current,
            @PathVariable Long limit,
            @RequestBody RechargeOrderInfoQueryVo rechargeOrderInfoQueryVo
    ) {
        Page<RechargeOrderInfo> page = this.rechargeOrderInfoService.selectRechargeOrderInfoPage(current, limit, rechargeOrderInfoQueryVo);
        return Result.ok(page);
    }

    @PostMapping("update")
    public Result update(@RequestBody RechargeOrderInfo rechargeOrderInfo) {
        boolean flag = this.rechargeOrderInfoService.updateById(rechargeOrderInfo);
        return flag ? Result.ok() : Result.fail();
    }

    @GetMapping("show/{id}")
    public Result show(@PathVariable Long id) {
        RechargeOrderInfo rechargeOrderInfo = this.rechargeOrderInfoService.show(id);
        return Result.ok(rechargeOrderInfo);
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        boolean flag = this.rechargeOrderInfoService.removeById(id);
        return flag ? Result.ok().message("删除成功") : Result.fail().message("删除失败");
    }

    @PostMapping("getMonthlyReport")
    public Map<String, Object> getMonthlyReport(@RequestBody RechargeOrderReportQueryVo rechargeOrderReportQueryVo) {
        return this.rechargeOrderInfoService.getMonthlyReport(rechargeOrderReportQueryVo);
    }

    @PostMapping("getQuarterlyReport")
    public Map<String, Object> getQuarterlyReport(@RequestBody RechargeOrderReportQueryVo rechargeOrderReportQueryVo) {
        return this.rechargeOrderInfoService.getQuarterlyReport(rechargeOrderReportQueryVo);
    }

    @GetMapping("getAnnualReport")
    public Map<String, Object> getAnnualReport() {
        return this.rechargeOrderInfoService.getAnnualReport();
    }
}

